package com.zkt.club.gateway.auth;

import cn.dev33.satoken.reactor.filter.SaReactorFilter;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 赵开泰
 * @program jc-club
 * @date 2025/3/21 22:10
 * @description [Sa-Token 权限认证] 配置类
 **/

@Configuration
public class SaTokenConfigure {
	// 注册 Sa-Token全局过滤器
	@Bean
	public SaReactorFilter getSaReactorFilter() {
		return new SaReactorFilter()
				// 拦截地址
				.addInclude("/**")
				// 鉴权方法：每次访问进入
				.setAuth(obj -> {
					// 拦截
					SaRouter.match("/auth/**").notMatch("/auth/user/login", "/auth/user/register").check(r -> StpUtil.checkLogin());
					SaRouter.match("/oss/**", r -> StpUtil.checkLogin());
					SaRouter.match("/subject/**", r -> StpUtil.checkLogin());
					SaRouter.match("/practice/**", r -> StpUtil.checkLogin());
					SaRouter.match("/recommend/**", r -> StpUtil.checkLogin());
				});
	}
}